home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 October / MACPOWER-1997-10.ISO.7z / MACPOWER-1997-10.ISO / AMUG / PROGRAMMING / Mac F2C 1.3.5.sit / Mac F2C 1.3.5 / Mac F2C Libraries / libI77 Sources / wsfe.c < prev    next >
Text File  |  1995-01-28  |  2KB  |  85 lines

  1. /*write sequential formatted external*/
  2. #include "f2c.h"
  3. #include "fio.h"
  4. #include "fmt.h"
  5. extern int f__hiwater;
  6.  
  7. #ifdef KR_headers
  8. x_putc(c)
  9. #else
  10. x_putc(int c)
  11. #endif
  12. {
  13.     /* this uses ¥n as an indicator of record-end */
  14.     if(c == '¥n' && f__recpos < f__hiwater) {    /* fseek calls fflush, a loss */
  15. #ifndef NON_UNIX_STDIO
  16.         if(f__cf->_ptr + f__hiwater - f__recpos < buf_end(f__cf))
  17.             f__cf->_ptr += f__hiwater - f__recpos;
  18.         else
  19. #endif
  20.             (void) fseek(f__cf, (long)(f__hiwater - f__recpos), SEEK_CUR);
  21.     }
  22. #ifdef OMIT_BLANK_CC
  23.     if (!f__recpos++ && c == ' ')
  24.         return c;
  25. #else
  26.     f__recpos++;
  27. #endif
  28.     return putc(c,f__cf);
  29. }
  30. x_wSL(Void)
  31. {
  32.     (*f__putn)('¥n');
  33.     f__recpos=0;
  34.     f__cursor = 0;
  35.     f__hiwater = 0;
  36.     return(1);
  37. }
  38. xw_end(Void)
  39. {
  40.     if(f__nonl == 0)
  41.         (*f__putn)('¥n');
  42.     f__hiwater = f__recpos = f__cursor = 0;
  43.     return(0);
  44. }
  45. xw_rev(Void)
  46. {
  47.     if(f__workdone) (*f__putn)('¥n');
  48.     f__hiwater = f__recpos = f__cursor = 0;
  49.     return(f__workdone=0);
  50. }
  51.  
  52. #ifdef KR_headers
  53. integer s_wsfe(a) cilist *a;    /*start*/
  54. #else
  55. integer s_wsfe(cilist *a)    /*start*/
  56. #endif
  57. {    int n;
  58.     if(!f__init) f_init();
  59.     if(n=c_sfe(a)) return(n);
  60.     f__reading=0;
  61.     f__sequential=1;
  62.     f__formatted=1;
  63.     f__external=1;
  64.     f__elist=a;
  65.     f__hiwater = f__cursor=f__recpos=0;
  66.     f__nonl = 0;
  67.     f__scale=0;
  68.     f__fmtbuf=a->cifmt;
  69.     f__curunit = &f__units[a->ciunit];
  70.     f__cf=f__curunit->ufd;
  71.     if(pars_f(f__fmtbuf)<0) err(a->cierr,100,"startio");
  72.     f__putn= x_putc;
  73.     f__doed= w_ed;
  74.     f__doned= w_ned;
  75.     f__doend=xw_end;
  76.     f__dorevert=xw_rev;
  77.     f__donewrec=x_wSL;
  78.     fmt_bg();
  79.     f__cplus=0;
  80.     f__cblank=f__curunit->ublnk;
  81.     if(f__curunit->uwrt != 1 && f__nowwriting(f__curunit))
  82.         err(a->cierr,errno,"write start");
  83.     return(0);
  84. }
  85.